package com.situ.controller.role;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.entity.might.SysMight;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.service.role.SysRoleService;
import com.situ.entity.role.SysRole;
import com.situ.util.*;

import java.util.List;

/**
 * SysRole的路由接口服务
 * 
 * @author胡文
 *
 */
//
@RestController
public class SysRoleController {

	/** SysRoleService服务 */
	@Autowired
	private SysRoleService sysRoleService;
	
	/**
	 * 查询所有SysRole数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "/SysRole/query", produces = {"application/json;charset=UTF-8"})
	public ResponseData query(SysRole value) {

		return ResponseData.ok().putDataValue("list",sysRoleService.find(value));
	}
	
	/**
	 * 通过id查询SysRole数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SysRole/queryById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData queryById(@PathVariable(name="id") Long id) {
		 return ResponseData.ok().putDataValue("obj",sysRoleService.findOne(id));
	}
	
	/**
	 * 插入SysRole属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SysRole/save")
	public ResponseData save(SysRole value) {
		return ResponseData.ok().putDataValue("obj", sysRoleService.saveNotNull(value));
	}
	
	/**
	 * 更新SysRole属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SysRole/update", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(SysRole value) {
		return ResponseData.ok().putDataValue("obj",sysRoleService.updateNotNullById(value));
	}

	/**
	 * 通过id删除SysRole数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SysRole/delById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delById(@PathVariable(name="id") Long id) {
		return ResponseData.ok().putDataValue("obj",sysRoleService.deleteById(id));
	}


    //带分页的查询全部
//@ApiOperation("带分页的查询全部")
    @RequestMapping(value = "/SysRole/queryPage", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage(SysRole value,
                             @RequestParam(defaultValue = "1",required = false) int pageNum ,
                             @RequestParam(defaultValue = "5",required = false) int pageSize) {

	    PageHelper.startPage(pageNum, pageSize);
        List<SysRole> list = sysRoleService.queryByLike(value);
    PageInfo pageInfo = new PageInfo<SysRole>(list,5);

        return ResponseData.ok()
        // .putDataValue("list", list)
        .putDataValue("pageInfo",pageInfo);
        }

    //全查所有的角色
    @RequestMapping(value = "/queryAllRoles", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryAllRoles(){
        return ResponseData.ok().putDataValue("role",sysRoleService.queryAllRoles());
    }
    //编辑角色保存
    @RequestMapping(value = "/updateRole", produces = {"application/json;charset=UTF-8"})
    public ResponseData updateRole(SysRole sysRole){
        return ResponseData.ok().putDataValue("i",sysRoleService.updateRole(sysRole));
    }
    //删除角色
    @RequestMapping(value = "/deleteRole/{roleId}", produces = {"application/json;charset=UTF-8"})
    public ResponseData deleteRole(@PathVariable Long roleId){
        return ResponseData.ok().putDataValue("i",sysRoleService.deleteRole(roleId));
    }
    //新建角色
    @RequestMapping(value = "/addRole", produces = {"application/json;charset=UTF-8"})
    public ResponseData addRole(SysRole sysRole){
        return ResponseData.ok().putDataValue("i",sysRoleService.addRole(sysRole));
    }
}
